<br>
<br>
<br>
<div class="row">
    <div class="col-xs-12 col-md-12">
        <div class="grid simple">
            <div class="grid-body no-border">
                <form action="<?= DOMAIN.'role/add' ?>" method="POST"> 
                    <div class="row">
                            <div class="row form-row">
                                <div class="col-xs-4 col-md-4">
                                    <label class="form-label">角色名 *</label>
                                    <input type="text" value="<?= $temp['name'] ?>" name="name" class="form-control" placeholder="只能包含英文或数字, 6~20位">
                                </div> 
                            </div>
                            <br>
                            <div class="row form-row">
                                <div class="col-xs-12 col-md-12">
                                    <label class="form-label">拥有权限</label>
                                    <? if($role_resource): ?>
                                        <table class="table table-bordered no-more-tables">
                                            <colgroup>
                                                <col />
                                                <col width="10%" />
                                            </colgroup>
                                            <thead>
                                                <tr>
                                                    <th>程序名</th>
                                                    <th>操作</th>
                                                    <? foreach($role_resource_group as $item): ?>
                                                        <th><?= $item ?></th>
                                                    <? endforeach ?>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <? foreach($role_resource as $r): ?>
                                                    <tr>
                                                        <td>
                                                            <?= $r['name'] ?>
                                                        </td>
                                                        <td>
                                                            <a href="javascript:void(0)" onclick="$.Add_role.select_all(this)">
                                                                全选
                                                            </a>
                                                            &nbsp;
                                                            <a href="javascript:void(0)" onclick="$.Add_role.select_none(this)">
                                                                反选
                                                            </a>
                                                        </td>
                                                        <? foreach($role_resource_group as $rg => $rgv): ?>
                                                        <td>
                                                            <? $id = "PRIV-{$r['resource_id']}-{$rg}" ?>
                                                            <div class="checkbox check-success">
                                                                <? if(is_array($temp['privs']) && in_array("{$r['resource_id']}-{$rg}", $temp['privs'])): ?>
                                                                    <? $checked = 'checked="checked"' ?>
                                                                <? else: ?>
                                                                    <? $checked = '' ?>
                                                                <? endif ?>
                                                                <input type="checkbox" <?= $checked ?> value="<?= "{$r['resource_id']}-{$rg}" ?>" name="privs[]" id="<?= $id ?>">
                                                                <label for="<?= $id ?>"></label>
                                                            </div>
                                                        </td>
                                                        <? endforeach ?>
                                                    </tr>
                                                <? endforeach ?>
                                            </tbody>
                                        </table>
                                    <? endif ?>
                                </div> 
                            </div>
                            <br>
                            <div class="row form-row">
                                <div class="col-xs-8 col-md-4">
                                    <label class="form-label">用户</label>
                                    <select name="admins[]" class="select2" style="width:100%" multiple>
                                        <? foreach($admin as $a): ?>
                                            <? if(is_array($temp['admins']) && in_array($a['admin_id'], $temp['admins'])): ?>
                                                <? $selected = 'selected="selected"' ?>
                                            <? else: ?>
                                                <? $selected = '' ?>
                                            <? endif ?>
                                            <option <?= $selected ?> value="<?= $a['admin_id'] ?>">
                                                <?= $a['nickname'] ?>
                                            </option>
                                        <? endforeach ?>
                                    </select>
                                </div> 
                            </div>
                    </div>
                      
                    <div class="form-actions">  
                        <div class="pull-left">
                            <button class="btn btn-success btn-cons" type="submit">
                                <i class="icon-save"></i>&nbsp;保存</button>
                            </button>
                            <button class="btn btn-white btn-cons" type="button" onclick="$.T.reset_form(this)">
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $.Add_role = {
        /**
         * [全选]
         */
        select_all: function(obj) {
            $(obj).parents('tr').find('input').attr('checked',true);
        },

        /**
         * [反选]
         */
        select_none: function(obj) {
            $(obj).parents('tr').find('input').attr('checked',false);
        },
    }
</script>